/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.example.touch.wifipositioning;


public class DistanceCalculator {
        
    
    public static double calcDistance(TraceEntry offline, TraceEntry online, int numberOfSamples) 
    {        
        int i = 0; 

        double dist = 0;

		
        for(MACAddress mOnline : online.getSignalStrengthSamples().getSortedAccessPoints()) {

            if(i > numberOfSamples)
            {
            	break;
            }
               

            double signalStrengthOffline = 0;
            double signalStrengthOnline = 0;

            if(offline.getSignalStrengthSamples().containsKey(mOnline) == false) 
            {
                //dist = Double.MAX_VALUE;
                continue;
            }

            signalStrengthOffline = offline.getSignalStrengthSamples().getAverageSignalStrength(mOnline);
            signalStrengthOnline = online.getSignalStrengthSamples().getAverageSignalStrength(mOnline);

            dist += Math.pow(signalStrengthOnline - signalStrengthOffline, 2);
            i++;
        }

        dist = Math.sqrt(dist);

        return dist;
    }

}
